package com.scaffold.service.impl;

import com.scaffold.client.impl.CaffeineCacheClient;
import com.scaffold.model.domain.UserDO;
import com.scaffold.manager.UserManager;
import com.scaffold.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Da Shuai
 * @since 2021-08-21 16:12:13
 */
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

    private final UserManager userManager;
    private final CaffeineCacheClient client;

    @Override
    public UserDO save(UserDO userPost) {
        userManager.saveUser(userPost);
        return userManager.getUserById(userPost.getId());
    }

    @Override
    public void deleteById(Long id) {
        userManager.deleteUserById(id);
    }

    @Override
    public UserDO update(UserDO userPut) {
        userManager.updateUser(userPut);
        return userManager.getUserById(userPut.getId());
    }

    @Override
    public UserDO getById(Long id) {
        return userManager.getUserIncludeDeleteById(id);
    }

    @Override
    public List<UserDO> list() {
        return userManager.listUser(null);
    }
}
